package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.dtos.ChannelNameDto;
import com.heima.model.admin.dtos.ChannelPageDto;
import com.heima.model.article.dtos.AuthorDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {

    @Autowired
    private AdChannelService adChannelService;

    @GetMapping("/channels")
    public ResponseResult<List> channels(){
        return ResponseResult.ok(adChannelService.list());
    }
    /**
     * 分页查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ChannelPageDto dto){
        return adChannelService.pageList(dto);
    }

    /**
     * 频道新增
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ChannelDto dto){
        return adChannelService.saveChannel(dto);

    }

    /**
     * 修改频道
     * @param dto
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody ChannelDto dto){
        return adChannelService.updateChannel(dto);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Long id){
        return adChannelService.delete(id);
    }

    /**
     * 查询频道id
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public ChannelNameDto findOne(@PathVariable Integer id){

        return adChannelService.findOne(id);
    }


}
